]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
workspace: Allow allocating smaller sizes for window clones
authorJonas Dreßler <verdre@v0yd.nl>
Mon, 1 Jun 2020 12:36:08 +0000 (14:36 +0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 2 Jun 2020 23:03:06 +0000 (23:03 +0000)
Change the preferred size functions of the layout manager of window
clones to allow allocating smaller sizes, too. Also scale down the
allocation sizes of the ClutterClones our allocate implementation so
the ClutterClones will scale their texture accordingly.

This will enable us to position the window clones using their allocation
size instead of their scale, which is necessary when introducing a new
ClutterLayoutManager that positions the window clones.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1294

js/ui/workspace.js

index 0830e29fb99549bd8e2f1e3f120e9dc5125c738b..960514911587fc2dfcc83883710433d27c230fc4 100644 (file)
@@ -51,35 +51,22 @@ class WindowCloneLayout extends Clutter.LayoutManager {
         this.layout_changed();
     }
 
-    _makeBoxForWindow(window) {
-        // We need to adjust the position of the actor because of the
-        // consequences of invisible borders -- in reality, the texture
-        // has an extra set of "padding" around it that we need to trim
-        // down.
-
-        // The bounding box is based on the (visible) frame rect, while
-        // the buffer rect contains everything, including the invisible
-        // border padding.
-        let bufferRect = window.get_buffer_rect();
-
-        let box = new Clutter.ActorBox();
-
-        box.set_origin(bufferRect.x - this._boundingBox.x,
-                       bufferRect.y - this._boundingBox.y);
-        box.set_size(bufferRect.width, bufferRect.height);
-
-        return box;
-    }
-
     vfunc_get_preferred_height(_container, _forWidth) {
-        return [this._boundingBox.height, this._boundingBox.height];
+        return [0, this._boundingBox.height];
     }
 
     vfunc_get_preferred_width(_container, _forHeight) {
-        return [this._boundingBox.width, this._boundingBox.width];
+        return [0, this._boundingBox.width];
     }
 
-    vfunc_allocate(container, _box) {
+    vfunc_allocate(container, box) {
+        // If the scale isn't 1, we weren't allocated our preferred size
+        // and have to scale the children allocations accordingly.
+        const scaleX = box.get_width() / this._boundingBox.width;
+        const scaleY = box.get_height() / this._boundingBox.height;
+
+        const childBox = new Clutter.ActorBox();
+
         container.get_children().forEach(child => {
             let realWindow;
             if (child == container._windowClone)
@@ -87,7 +74,20 @@ class WindowCloneLayout extends Clutter.LayoutManager {
             else
                 realWindow = child.source;
 
-            child.allocate(this._makeBoxForWindow(realWindow.meta_window));
+            const bufferRect = realWindow.meta_window.get_buffer_rect();
+            childBox.set_origin(
+                bufferRect.x - this._boundingBox.x,
+                bufferRect.y - this._boundingBox.y);
+
+            const [, , natWidth, natHeight] = child.get_preferred_size();
+            childBox.set_size(natWidth, natHeight);
+
+            childBox.x1 *= scaleX;
+            childBox.x2 *= scaleX;
+            childBox.y1 *= scaleY;
+            childBox.y2 *= scaleY;
+
+            child.allocate(childBox);
         });
     }
 });